import vue from '@vitejs/plugin-vue';
import laravel from 'laravel-vite-plugin';
import path from 'path';
import tailwindcss from '@tailwindcss/vite';
import {defineConfig} from 'vite';
import vueJsx from '@vitejs/plugin-vue-jsx';
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import {ArcoResolver} from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

export default defineConfig({
    plugins: [
        laravel({
            input: [ 'resources/css/app.css','resources/js/entries/app.ts'],
            ssr: 'resources/js/entries/ssr.ts',
            refresh: true,
        }),
        tailwindcss(),
        vue({
            template: {
                transformAssetUrls: {
                    base: null,
                    includeAbsolute: false,
                },
            },
        }),
        vueJsx(),
        AutoImport({
            resolvers: [ArcoResolver()],
            imports: ['vue'],
            dts: 'resources/js/types/auto-import.d.ts',
        }),
        Components({
            resolvers: [
                ArcoResolver({
                    sideEffect: false,
                }),
            ],
            dirs: ['resources/js/components'],
            extensions: ['vue', 'tsx'],
            dts: 'resources/js/types/components.d.ts',
        }),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(__dirname, 'resources/js/assets/icons')],
            symbolId: 'icon-[name]',
        }),
    ],
    resolve: {
        alias: {
            '@': '/resources/js',
            '/static': '/public/static',
            'ziggy-js': path.resolve('vendor/tightenco/ziggy'),
        },
    },
    build: {
        chunkSizeWarningLimit: 2000, // 消除打包大小超过500kb警告
        minify: 'esbuild', // Vite 2.6.x 以上需要配置 minify："terser"，terserOptions才能生效
    },
});
